#include <accent/algorithms/take_while.hpp>
#include "test_base.hpp"

auto take_p(ivec& v) -> decltype(take_while(positive(), all(v)))
{
  return take_while(positive(), all(v));
}

TEST(TakeWhile, emptyRange_isEmpty)
{
  ivec v;
  auto r = take_p(v);
  ASSERT_TRUE(r.empty());
}

TEST(TakeWhile, firstWrong_isEmpty)
{
  ivec v = { -1 };
  auto r = take_p(v);
  ASSERT_TRUE(r.empty());
}

TEST(TakeWhile, firstRight_notEmpty)
{
  ivec v = { 1 };
  auto r = take_p(v);
  ASSERT_FALSE(r.empty());
}

TEST(TakeWhile, rightWrong_popFront_isEmpty)
{
  ivec v = { 1, -1 };
  auto r = take_p(v);
  r.pop_front();
  ASSERT_TRUE(r.empty());
}

TEST(TakeWhile, rightRight_popFront_notEmpty)
{
  ivec v = { 1, 1 };
  auto r = take_p(v);
  r.pop_front();
  ASSERT_FALSE(r.empty());
}

TEST(TakeWhile, rightRight_valuesCorrect)
{
  ivec v = { 1, 2 };
  auto r = take_p(v);
  ASSERT_EQ(1, r.front());
  r.pop_front();
  ASSERT_EQ(2, r.front());
}
